package com.example.myapplication;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.adapter.MyAdapter;
import com.example.myapplication.bean.UserBean;

public class SecondHomeFragment extends Fragment {
    private View view;
    private RecyclerView mRecyclerView;
    private MyAdapter myAdapter;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.activity_recyclerview, container, false);
        initRecyclerView();
        initData();
        return view;

    }

    private void initData() {
        for (int i = 0; i < 10; i++) {
            UserBean bean = new UserBean();
            bean.setHeadID(R.drawable.label_1);
            bean.setUserName("一个程序员的水平能差到什么程度？");
            bean.setRead("1277万热度");
            bean.setBottomID(R.drawable.iocn_1);
            myAdapter.addData(bean);
        }
    }

    private void initRecyclerView() {
        mRecyclerView = (RecyclerView)view.findViewById(R.id.rv_content);
        LinearLayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(manager);

        myAdapter = new MyAdapter();
        mRecyclerView.setAdapter(myAdapter);
    }
}
